package com.wxy.netty.eventLoop;

import io.netty.channel.DefaultEventLoopGroup;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;

import java.sql.SQLOutput;
import java.util.concurrent.TimeUnit;

/**
 * @author 47868
 */
public class 普通_定时任务 {
    public static void main(String[] args) {
        System.out.println(Thread.currentThread().getName());
        //普通任务 定时任务 server 容量为2 两个线程循环执行
        EventLoopGroup eventLoopGroup = new NioEventLoopGroup(2);
        //普通任务 定时任务
        //EventLoopGroup eventLoopGroup2 = new DefaultEventLoopGroup();
        System.out.println(eventLoopGroup.next());
        System.out.println(eventLoopGroup.next());
        System.out.println(eventLoopGroup.next());
        System.out.println(eventLoopGroup.next());
        //执行普通任务
        eventLoopGroup.next().submit(()->{
            System.out.println(Thread.currentThread().getName()+" 普通任务...");
        });
        //执行定时任务
        eventLoopGroup.next().schedule(() -> System.out.println(Thread.currentThread().getName()+" 定时任务..."),1,TimeUnit.SECONDS);

        //执行定时循环任务
        eventLoopGroup.next().scheduleAtFixedRate(() -> System.out.println(Thread.currentThread().getName()+" ok"),0,1, TimeUnit.SECONDS);
    }
}
